%by clq
%2021/6/12
function[i_RP,profits_R]=RoundRobinPref(I,J,j_all)
%I is the number of slots (I is even),J is the types of patients
%j_all is the given order of patient types
addpath functions;
n=size(j_all,2);

%Step1: decide the preference randomly


%Step2:find the optimal slot for each patient
for ii = 1 : 100
    disp(ii);
    S=zeros(I,J);
    j=0;k=0;
    pref=randi([1,2],1,n);
    for i=1:n
        pref_temp=pref(i);
        if pref_temp==1
        j=j+1;
        i_RP(i)=mod(j-1,I/2)+1;
        else
        k=k+1;
        i_RP(i)=mod(k-1,I/2)+5;
        end
    end
    %Step3:find the profit after each patient is assigned
    for i=1:n
        j=j_all(i);
        S(i_RP(i),j)=S(i_RP(i),j)+1;
        Q = findQ(S); 
        R = findR(Q);
        profits_R(ii, i)=function_fQR(Q,R);
    end
end
profits_R = mean(profits_R, 1)